import time
from multiprocessing import Process
import os
class Sub_p(Process):
    # 初始化
    def __init__(self, name):
        super().__init__()
        self.name = name
    # 重写run方法
    def run(self):
        print("子进程名称:", self.name, "pid:", os.getpid(), "父进程pid:", os.getppid())

if __name__ == '__main__':
    # 主进程
    print("主进程开始执行")
    lst  = []
    for i in range(5):
        p1 = Sub_p(f"进程{i+1}")
        # 启动进程
        p1.start()
        lst.append(p1)
    for i in lst:
        i.join()
    print("主线程执行完毕")
